<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="采集时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 360px"
          value-format="timestamp"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="alarmList.slice((currentPage1-1)*pageSize,currentPage1*pageSize)">
      <el-table-column label="序号" type="index" width="50" align="center"/>
      <el-table-column label="测点名称" align="center" prop="pointName" width="200" show-overflow-tooltip/>
      <el-table-column label="测点描述" align="center" prop="description" width="180" show-overflow-tooltip/>
      <el-table-column label="全局名称" align="center" prop="globalName" width="180" show-overflow-tooltip/>
      <el-table-column label="查询时间" align="center" prop="callTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.callTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="采集值" align="center" prop="value">
        <template slot-scope="scope">
          <span>{{ parseFloat(scope.row.value).toFixed(2) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="采集时间" align="center" prop="time">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态改变时间" align="center" prop="eventChangeTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.eventChangeTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :background="true"
        :current-page="currentPage1"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

  </div>
</template>

<script>
import { listAlarm } from '@/api/collection/alarm'

export default {
  name: 'Alarm',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      currentPage1: 1,
      pageSize: 10,
      // 参数表格数据
      alarmList: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        dateFrom: undefined,
        dateTo: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  mounted() {
  },
  methods: {
    getList() {
      this.loading = true
      if (this.dateRange && this.dateRange.length > 0) {
        this.queryParams.dateFrom = this.dateRange[0]
        this.queryParams.dateTo = this.dateRange[1]
      } else {
        this.queryParams.dateFrom = null
        this.queryParams.dateTo = null
      }
      listAlarm(this.queryParams).then(res => {
        this.alarmList = res.data
        this.total = res.data.length
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    handleSizeChange(val) {
      //一页显示多少条
      this.pageSize = val
    },
    handleCurrentChange(val) {
      //默认第一页，当你点击就把点击的那页赋值给currentPage1
      this.currentPage1 = val
    }
  }
}
</script>

<style scoped lang="scss">

</style>
